using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;

namespace Avanzis.Helpers.QueryBuilder.Nunit.Common
{
    [TestFixture]
    public class StringExpressionTest
    {
        [Test]
        public void SimpleStringExpression()
        {
            StringExpression se1 = new StringExpression("Active = 1");
            Assert.AreEqual("Active = 1", se1.ToString());

            se1.Expression = "NotActive = 2";
            Assert.AreEqual("NotActive = 2", se1.ToString());
            
        }
        [Test]
        public void TestClone()
        {
            StringExpression se1 = new StringExpression("Active = 1");
            StringExpression se2 = (StringExpression)se1.Clone();
            Assert.AreEqual(se1.Expression, se2.Expression);                        
        }

        [Test]
        public void TestGetStringValue()
        {
            // Booleano
            Assert.AreEqual("1", StringExpression.GetStringValue(true));
            Assert.AreEqual("0", StringExpression.GetStringValue(false));
            // DateTime
            Assert.AreEqual("'19770121 22:23:45'", StringExpression.GetStringValue(new DateTime(1977, 01, 21, 22, 23, 45)));
            // Null
            Assert.AreEqual("''", StringExpression.GetStringValue(null));
            // String
            Assert.AreEqual("Hola", StringExpression.GetStringValue("Hola"));
            Assert.AreEqual("'Hola'", StringExpression.GetStringValue("'Hola'"));
            Assert.AreEqual("'Ho''la'", StringExpression.GetStringValue("Ho'la", true));

            // Double
            double testDouble = 23.45;
            Assert.AreEqual("23.45", StringExpression.GetStringValue(testDouble));
            // Float
            float testFloat = 56.78F;
            Assert.AreEqual("56.78", StringExpression.GetStringValue(testFloat));


        }

    }
}
